<?php
require_once 'include/Database.php';
require_once 'include/SQLQuery.php';

class LoginDatabase extends Database
{
   private $_encryptionKey;

   function __construct($s, $un, $p, $d, $k, $t, $tf)
   {
      $this->_encryptionKey = $k;
      parent::__construct($s, $un, $p, $d, $t, $tf);
   }
  
   public function getKey()
   {
      return $this->_encryptionKey;
   }

   public function login($n, $p, $fieldID, $fieldPassword)
   {
      $query = new SQLQuery();
      $query->selectConjunction($this->getTableName(),
                                array($fieldID, 
                                      $fieldPassword),
                                array($fieldID=>$n, 
                                      SQLQuery::decrypt($fieldPassword, 
                                                         $this->getKey())=>$p),
                                1);
      $result=$this->query($query->request());
      if($result->num_rows == 1)
      {   
         return true;
      }
      else 
      {
        return false;
      }
   }

}
?>